
<?php 
//echo $this->Html->script('libs/fixed-header-table/jquery.fixedheadertable.min.js',
//                         array('inline' => false));
    $options = array('inline'=>false);
    echo $this->Html->css("menu_tight",null,$options);
    
    //echo $this->Html->script('libs/jQueryLayout/jquery.layout.min.js', $options);
    //echo $this->Html->css("/js/libs/jQueryLayout/layout-default.css",null,$options);
    
?>

<div class="ui-layout-container jobs view panel">
 <div class="ui-layout-center my-ui-layout-pane">
  <div id="centerContent">
  <!-- Job Details (group, name, alt name, descrip, etc) -->
  <dl>
    <div id="jobNameDiv">
      <dt class="heading">Job</dt>
      <dd ><strong><h3 id="jobName"><?php echo $job['Job']['name']; ?></h3></strong></dd>
    </div>
    <div class="altrow">
      <dt>Group</dt>
      <dd><?php echo $job['JobGroup']['name']; ?></dd>
    </div>
    
    <?php // Alternate Job Name 
    if(isset($job['JobAltName']['name'])): ?>
    <dt>Alternate Name</dt>
    <dd><?php echo "{$job['JobAltName']['name']}"; ?></dd>
    <?php endif; ?>
    
    <?php // Description
    if(isset($job['Description']['content'])): ?>
    <div class="altrow">
      <dt>Description</dt>
      <dd id="description"><?php echo "{$job['Description']['content']}"; ?></dd>
    </div>
    <?php endif; ?>
    
  </dl>
  
  <!-- "Edit Job", "Delete Job", "Add New Default Version" buttons for this Job -->
  <!-- <div class="actions jobActions">-->
  <div id="jobActions">  
    
    <ul class="menuTight shadow3">
      <?php
      // define some empty vars for passing to method for code readability (rather than passing 'null')
      $linkArgs     = null;  $separateArgs = null;   $subList = null;  $confirmMsg = null;
      $linkOptions = array();   $imgOptions =  array('class'=>'icon'); 

      // "Edit Job" menu item
      $isFirstTopMenuItem = true; $isLastTopMenuItem  = false;
      $linkDisplayStr = 'Edit Job';   $tooltip = '';
      $iconPath = 'Icons/White/NoCircle/32x32/pencil.png'; 
      $linkToController = 'jobs';         $linkToMethod = 'form';
      $linkArgs = array($job['Job']['id'], /* template_version_id: */ "dummy", // Can't use null
                                           /* edit_job_id: */ $job['Job']['id']);
      $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
      echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                            $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                            $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg );
      
      // "Delete" version menu item
      $isFirstTopMenuItem = false; $isLastTopMenuItem  = true;
      $linkDisplayStr = 'Delete Job'; $tooltip = 'Delete Job and all its Job Versions';
      $iconPath = 'Icons/White/NoCircle/32x32/trash.png'; 
      $linkToController = 'jobs';         $linkToMethod = 'delete';
      $linkArgs = array($job['Job']['id']);
      $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
      $confirmMsg = "Are you sure you want to delete Job '{$job['Job']['name']}' AND all its Versions?";
      echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                            $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                            $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg ); 
      $confirmMsg = null; // reset for next btn
      ?>
    </ul>
    <ul class="menuTight shadow3" id="newDefaultVersionBtn">
      <?php
      // "New Default Version" menu item
      $isFirstTopMenuItem = true; $isLastTopMenuItem  = true;
      $linkDisplayStr = 'Default Version';   $tooltip = 'New Version with all default param values';
      $iconPath = 'Icons/White/NoCircle/24x24/plus.png'; 
      $linkToController = 'jobs';         $linkToMethod = 'form';
      $linkArgs = array($job['Job']['id']);
      $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
      echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                            $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                            $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg );   
      ?>
    </ul>
    
  </div>
  <!-- Job Version header stuff -->
  <h3 id="jobVersionsHeading">Job Versions</h3>
  
  <table id="jobVersionsTable" class="panel">
    <thead>
      <tr>
        <th class="blank"></th>
        <th>Version Num</th>
        <th>Version Name</th>
        <th>Job Type</th>
        <th>Author</th>
        <th>Created</th>
        <th>Status</th>
      </tr>
    </thead>
    
    <tfoot>
      <tr class="blank">
        <td></td>
      </tr>
    </tfoot>

    <?php
    ///////////////////////////////////////////////////////////////////////////////
    //// List all Job Versions  ///////////////////////////////////////////////////
    $i = 0;
    foreach ($jobVersions as $version):
      $class       = null;
      $altrowClass = null;
      $jobClass = "_{$version['JobVersion']['job_id']}";
      if ($i++ % 2 == 0) {
        $altrowClass = 'altrow';
      }
      $class = 'class="' .$jobClass . " " . $altrowClass . '"';
    ?>
    <tbody class="rowWrapper">    
      <tr <?php echo $class; ?>> 
        <!-- "New Version Like This" link that appears next to a JobVersion -->
        <th scope="row" class="newVersionLikeThis <?php echo $jobClass ?>">
          <?php  
            $likeThisHtmlAndText = 'New<span class="regTextFrosted">Version</span> 
                                   <p class="regTextFrosted smaller">Like This</p>';
            $url = array('action'=>'form', $job['Job']['id'], // Job that the new Version is assoc with
                                           $version['JobVersion']['id'] // template JobVersion to use 
                        );
            $options = array('escape'=> false);
            echo $this->Html->link( $likeThisHtmlAndText, $url, $options);
          ?> 
        </th>
        
        <!-- JobVersion data -->
        <td class="versionNum"><?php echo $version['JobVersion']['version_num']; ?>&nbsp;</td>
        <td><?php echo $version['JobVersionName']['name']; ?>&nbsp;</td>
        <td><?php echo $version['JobType']['name']; ?>&nbsp;</td>
        <td><?php echo $version['Author']['name']; ?>&nbsp;</td>
        <td><?php echo $version['JobVersion']['created']; ?>&nbsp;</td>
        <td><?php echo $version['Status']['name']; ?>&nbsp;</td>
      </tr>     
      
    
      <tr class="optionsRow">
        <td class="blank"></td>
        
        <td class="versionOptions" colspan="6">
          <!-- Job Version buttons menu "Edit", "Delete", "Fiji", "Details", etc -->
          <ul class="menuTight shadow2">
            <?php
            // define some empty vars for passing to method for code readability (rather than passing 'null')
            $linkArgs     = null;  $separateArgs = null;   $subList = null;  $confirmMsg = null;
            $linkOptions = array();   $imgOptions =  array('class'=>'icon');  
           
            // "See Details" version menu item
            $isFirstTopMenuItem = true; $isLastTopMenuItem  = false;
            $linkDisplayStr = 'Details';   $tooltip = 'See Detailed Parameters of this Job Version';
            $iconPath = 'Icons/White/NoCircle/32x32/tasks.png'; 
            // TEMP: link will go to the Edit Version view right now since it at least shows all params
            $linkToController = 'jobs';         $linkToMethod = 'form';
            $linkArgs = array($job['Job']['id'], /* template_version_id: */ "false", // Can't use null or boolean or Cake removes the arg
                               /* edit_job_id: */ "false",/* edit_job_version_id: */ $version['JobVersion']['id']);
            $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
 
            echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                                  $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                                  $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg ); 
            
            // "Launch Fiji" menu item      
            $isFirstTopMenuItem = false; $isLastTopMenuItem  = false;
            $linkDisplayStr = 'Launch Fiji';   $tooltip = 'Examine a set of images from this Job Version';
            $iconPath = 'Icons/White/NoCircle/32x32/taskmgr.png'; 
            $linkToController = '';         $linkToMethod = '';      $linkArgs = array();
            // I'm including some custom html attributes for each 'launch fiji' btn so that data
            // can be extracted via jQuery and used in an Ajax call to get approp images to open in fiji. 
            $linkOptions = array('class'=>'fiji', 'data-job_id'=>$job['Job']['id'],
                                                  'data-job_version_id'=>$version['JobVersion']['id'],
                                                  'data-is_input_data_preview'=>'false'); // it is for an 'output' preview, not input
            
            echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                                  $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                                  $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg ); 
             
            // "Edit" version menu item
            $isFirstTopMenuItem = false; $isLastTopMenuItem  = false;
            $linkDisplayStr = 'Edit';   $tooltip = 'Edit Version';
            $iconPath = 'Icons/White/NoCircle/32x32/pencil.png'; 
            $linkToController = 'jobs';         $linkToMethod = 'form';
            $linkArgs = array($job['Job']['id'], /* template_version_id: */ "false", // Can't use null or boolean or Cake removes the arg
                               /* edit_job_id: */ "false",/* edit_job_version_id: */ $version['JobVersion']['id']);
            $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
            $linkOptions = array(); // reset it
            echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                                  $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                                  $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg );  
            
            // "Delete" version menu item
            $isFirstTopMenuItem = false; $isLastTopMenuItem  = true;
            $linkDisplayStr = 'Delete'; $tooltip = 'Delete Version';
            $iconPath = 'Icons/White/NoCircle/32x32/trash.png'; 
            $linkToController = 'job_versions';         $linkToMethod = 'delete';
            $linkArgs = array($version['JobVersion']['id'], $job['Job']['id']);
            $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
            $linkOptions = array();   $imgOptions =  array('class'=>'icon');
            $confirmMsg = sprintf('Are you sure you want to delete Version # %s?', $version['JobVersion']['version_num']);
            
            echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                                  $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                                  $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg ); 
            ?>
          </ul>
          
        </td>
      </tr> <!-- end tr.optionsRow -->
      <!--
      <tr class="paramsRow">
        <td class="blank"></td>
        <td colspan ="6">
          <p>params will go in this row</p>
          <?php
          //debug($version); 
          ?>
        </td>
      </tr>
      -->
      
      <!-- Horizontal Rule divider between versions -->
      <tr class="blank"><td></td><td colspan="5"><hr /></td></tr>
    </tbody> <!-- end tbody.rowWrapper -->  
    <?php endforeach; ?>
      
  </table>
  </div> <!-- end #centerContent -->
 </div> <!-- end Center Panel -->

  <?php

//  App::import('Lib', 'headless_fiji_macro_executer');
//
//  // <editor-fold defaultstate="collapsed" desc="Prepare images (stacks) for Fiji">
//  $debug = 0; // use an int for the boolean so the argument str gets constructed correctly
//  // Get a new Strategy obj to handle calling the macro
//  $macExec = new HeadlessFijiMacroExecuter(/* debug: */ $debug);
//  /////////////////////////////////////////////////
//  /////// FITS MACRO  /////////////////////////////
//  $macExec->set_macro_name("CreateStack_Resample_from_FITS.ijm");
//  // Linux
//  if (GlobalsClass::getPlatform() == PlatformType::linux) {
//    $src_img_path = GlobalsClass::getImagesPath() . "Samples/";
//    $result_img_path = GlobalsClass::getImagesPath() . "Samples/";
//  }
//  // Windows
//  else if (GlobalsClass::getPlatform() == PlatformType::windows) {
//    $src_img_path = GlobalsClass::getImagesPath() . "Samples\\";
//    $result_img_path = GlobalsClass::getImagesPath() . "Samples\\";
//  }
//
//  $result_img_name = "stack_from_resampled_FITS.zip";
//  //$FITS_stack_with_rel_path = GlobalsClass::getImgPathRelToApplet()
//  //                            . "Samples/$result_img_name"; // used in html    
//  $FITS_stack_with_abs_path = GlobalsClass::getImagesPath() ."Samples/$result_img_name"; // used in html    
//  
//  $scale = 2; // downsample by factor of this
//
//  $args_array = array(/* debug: */ $debug, $src_img_path, $result_img_path,
//                       $result_img_name, $scale);
//
//  $args_str = $macExec->construct_macro_str($args_array, GlobalsClass::getMacroArgDelim());
//
//  $macExec->set_macro_arg_str($args_str);
//  //debug($macExec->get_macro_arg_str() );
//  //die($macExec->get_macro_arg_str() );
//  $macExec->execute_macro(); // creates the stack

  /////////////////////////////////////////////////
  /////// RAW MACRO  //////////////////////////////
  /*
  $macExec->set_macro_name("Convert_F32_to_Tiff.ijm");
  // Linux
  if (GlobalsClass::getPlatform() == PlatformType::linux) {
    $src_img_path = GlobalsClass::getImagesPath() . "Samples/";
    $result_img_path = GlobalsClass::getImagesPath() . "Samples/";
  }
  // Windows
  else if (GlobalsClass::getPlatform() == PlatformType::windows) {
    $src_img_path = GlobalsClass::getImagesPath() . "Samples\\";
    $result_img_path = GlobalsClass::getImagesPath() . "Samples\\";
  }
  $result_img_name = "stack_from_converted_RAW.zip";

  $RAW_stack_with_rel_path = GlobalsClass::getImgPathRelToApplet()
                             . "Samples/$result_img_name"; // used in html                                                        
  $scale = 2; // 2 means scale to 1/2
  $rawImgType = "32-bit Real";
  $rawWidth = 560;
  $rawHeight = 560;
  //$rawWidth   = 1024;
  //$rawHeight  = 768;
  $rawOffset = 0;
  $rawNumImgs = 1;
  $rawGapBetweenImgs = 0;
  ///// CONSTRUCT THE RAW MACRO ARGUMENT ///
  $args_array = array($debug, $src_img_path, $result_img_path, $result_img_name, $scale,
                      $rawImgType, $rawWidth, $rawHeight, $rawOffset,
                      $rawNumImgs, $rawGapBetweenImgs); // order of args matters!

  $args_str = $macExec->construct_macro_str($args_array, GlobalsClass::getMacroArgDelim());
  $macExec->set_macro_arg_str($args_str);
  $macExec->execute_macro(); // creates the stack   // </editor-fold>
  */
  ?>
  <div class="ui-layout-east my-ui-layout-pane">


    <div id="Fiji_Div"> <!-- to be filled in by AJAX result -->
    </div>

    
  </div><!-- end East Panel -->
  
</div>

